package com.cduestc.weatheractivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.cduestc.animation.ExitApp;

public class More extends AppCompatActivity {
    TextView tvAbout,tvExit,tvNightMode,tvFeedBack,tvCleanCache;
    ImageButton ibBackHome;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
        ExitApp exitApp = ExitApp.getInstance();
        exitApp.addActivity(this);
        ibBackHome = this.findViewById(R.id.ibBackHome);
        tvAbout = this.findViewById(R.id.tvAbout);
        tvExit = this.findViewById(R.id.tvExit);
        SharedPreferences shared,shared1;
        shared = this.getSharedPreferences("TrafficWarning",MODE_PRIVATE);
        shared1 = this.getSharedPreferences("LocalCity",MODE_PRIVATE);

        tvCleanCache = this.findViewById(R.id.tvCleanCache);
        tvNightMode = this.findViewById(R.id.tvNightMode);

        ibBackHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(More.this,HomePage.class);
                startActivity(intent);
                exitApp.onLowMemory();
                finish();
            }
        });

        tvAbout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(More.this,About.class);
                startActivity(intent);
                finish();
            }
        });

        tvExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences.Editor seDel = shared.edit();
                seDel.putString("Once","");
                seDel.commit();
                ExitApp ea = ExitApp.getInstance();
                ea.onLowMemory();
                ea.exit();
            }
        });

        tvCleanCache.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences.Editor seD = shared.edit();
                SharedPreferences.Editor seD1 = shared1.edit();
                seD.clear();
                seD.commit();
                seD1.clear();
                seD1.commit();
                Toast.makeText(More.this, "清除成功", Toast.LENGTH_SHORT).show();
            }
        });

        tvNightMode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(More.this,NightMode.class);
                startActivity(intent);
            }
        });

    }
}